package Demo5;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

public class Main10 {
    public static void main(String[] args) {
        BlockingQueue<String>queue=new LinkedBlockingQueue<>(100);
        Thread t1=new Thread(()->{
            for (int i = 0; i <1000 ; i++) {
                try {
                    queue.put("aaaaaa");
                    System.out.println("入队元素:aaaaaaa");
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        Thread t2=new Thread(()->{
            while(true){
                try {
                    String s=queue.take();
                    System.out.println("出队元素:"+s);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
t1.start();
t2.start();
    }
}
